#! /usr/bin/env python

import os
import getopt
import sys

def ch_do(path,callback):
	os.chdir(path)	
	ch_dirs = []
	try:
		ch_dirs = os.listdir(".")
	except:
		print "no such file or dir"
		return
	for ch in ch_dirs:
		if os.path.isdir(ch):
			print ch
			if ch == ".svn":
				callback(ch)
				break
			else:
				print ch
				ch_do(ch,cb)
	os.chdir("../")

def cb(dir_name):
	path = os.getcwd()
	print "current path:" + path
	os.system("rm -rf " + dir_name)

if "__main__" == __name__:
	path = ""
	opts,args = getopt.getopt(sys.argv[1:],"hp:",["help","path="])
	for o,a in opts:
		if o in ("-h","--help"):
			print "-h,--help get the progame help"
			print "-p,--path the work path,default is current path"
			sys.exit()
		elif o in ("-p","--path"):
			path = a
	if "" == path:
		path = os.getcwd()
	ch_do(path,cb)


 #import os
 #import shutil
 #import sys
 #import stat
 
 #def deleteSubFile(svnpath):
     #names = os.listdir(svnpath)
     #for name in names:
         
         #fp = os.path.join( svnpath, name)
         #if (os.path.isfile(fp)):
             #os.chmod( fp, stat.S_IWRITE)
             #os.remove(fp)
         #else:
             #deleteSubFile(fp)
             
 
 #def deleteSVN(parentPath = None, dir = None):
     #if (dir != None and dir == '.svn'):
         #deleteSubFile(os.path.join( parentPath, dir))
         #shutil.rmtree(os.path.join( parentPath, dir), True, False)
         #print 'deleted ', os.path.join( parentPath, dir)
     #else:
         #if (dir != None):
             #filePath = os.path.join( parentPath, dir)
         #else:
             #filePath = parentPath
         #names = os.listdir(filePath)
         #for name in names:
             #fp = os.path.join( filePath, name)
             #if (os.path.isdir(fp)):
                 #deleteSVN(filePath, name)
 
 
 #if len(sys.argv) < 2:
     #print 'Usage: python % <file path>' % os.path.basename(sys.argv[0])
     #sys.exit(-1)
 
 #if os.path.isfile(sys.argv[1]):
     #print "请选择文件夹不是文件" 
 #else:
 #    deleteSVN(parentPath = sys.argv[1])


#for (p,d,f) in os.walk("需要删除的文件#夹")
     #if p.find('.svn')>0:
         #os.popen('rd /s /q %s'%p)
